package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.StrategyCommend;
import cn.wolfcode.luowowo.article.mapper.StrategyCommendMapper;
import cn.wolfcode.luowowo.article.service.IStrategyCommendService;
import cn.wolfcode.luowowo.common.query.StrategyCommendQueryObject;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class StrategyCommendServiceImpl implements IStrategyCommendService{
    @Autowired
    private StrategyCommendMapper strategyCommendMapper;

    public PageInfo query(StrategyCommendQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<StrategyCommend> list = strategyCommendMapper.selectForList(qo);
        return new PageInfo(list);
    }

    public void deleteById(Long id) {
        strategyCommendMapper.deleteByPrimaryKey(id);
    }

    public void saveOrUpdate(StrategyCommend strategyCommend) {
        if(strategyCommend.getId() == null){
            //新增操作
            strategyCommendMapper.insert(strategyCommend);
        }else{
            //更新操作
            strategyCommendMapper.updateByPrimaryKey(strategyCommend);
        }
    }

    public List<StrategyCommend> selectAllCommends() {

        return strategyCommendMapper.selectAll();
    }

    public List<StrategyCommend> selectCommendsTop5() {

        return strategyCommendMapper.selectCommendsTop5();
    }
}
